package ITSBank;

import java.io.*;

public class ITSBank {
         
    public static void authenticate(Customer customer, BufferedReader klaw) throws IOException {
System.out.println("Enter your PIN code");
String s = klaw.readLine();
if (s.equalsIgnoreCase(customer.getPIN())){
customer.setTrusted(true);
}
    }

 //   public static void withdraw(Account account){

   // }

  //  public static void deposit(Customer cust, float amount){
//cust.account.Balance+=amount;
//    }

    //public static void AccountBalance(BufferedReader klaw,Customer cust) throws IOException{
    //    authenticate(cust,klaw);
    //    if (cust.trusted==true){
    //    System.out.println("You have:" + cust.account.getBalance());
    //    }
    //}

    public static void main(String[] args) throws IOException {

        Bank itsbank;
        itsbank = new Bank(1,"ITSBANK");

        BufferedReader keyb = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("ITS BANK");
       

System.out.println("Enter name for a new customer");
String ans1 = keyb.readLine();
System.out.println("Enter address for a new customer");
String ans2 = keyb.readLine();

        itsbank.newCustomer(ans1,ans2);
        
try{
System.out.println("Enter CustomersID for the customer you want to add Account to:");
int ans3 = Integer.parseInt(keyb.readLine());
System.out.println("What type of account do you want? (1:SavingAccount,2:CheckingAccount,3:CustodyAccount)");
int ans4 = Integer.parseInt(keyb.readLine());
//createAccount(startAmount:100,type:1,CustomerID:typed by keyboard)

itsbank.createAccount(ans4, ans3);}
catch(Exception e){System.err.println("Ooooops! Some mistake:"+e.getMessage());return;}

    try{
System.out.println("Enter AccountID for the account you want to make a deposit to:");
int ans3 = Integer.parseInt(keyb.readLine());
System.out.println("How much money?");
float ans5 = Float.parseFloat(keyb.readLine());

itsbank.getAccount(ans3).deposit(ans5);}
catch(Exception e){System.err.println("Ooooops! Some mistake:"+e.getMessage());return;}

try{
    //Now a withdraw with authentication:
    System.out.println("Enter AccountID for the account you want to make a withdraw from:");
    int ans3 = Integer.parseInt(keyb.readLine());
    System.out.println("Enter your CustomerID");
    int ans4 = Integer.parseInt(keyb.readLine());
    
    if (itsbank.getCustomer(ans4).getCustomerID()==itsbank.getAccount(ans3).getCustomerID())
    {authenticate(itsbank.getCustomer(ans4),keyb);
     if (itsbank.getCustomer(ans4).isTrusted()==true)
     {System.out.println("How much money?");
    float ans5 = Float.parseFloat(keyb.readLine());
    itsbank.getAccount(ans3).withdraw(ans5);}
     else{
     System.out.println("Wrong PIN!");return;}
    }
    else{
        System.out.println("You are not the owner of this account!");return;
    }}
    catch(Exception e){System.err.println("Ooooops! Some mistake:"+e.getMessage());return;}

    try{
    System.out.println("Enter CustomerID for the Customer you want to show details of:");
    int ans3 = Integer.parseInt(keyb.readLine());
   //System.out.println(itsbank.getAccount(ans3).getBalance());
    itsbank.getCustomer(ans3).ShowCustomerDetails();}
    catch(Exception e){System.err.println("Ooooops! Some mistake:"+e.getMessage());}

}
//  System.out.println(itsbank.Customers);
}


